import api from '../../utils/api'
const img1 = 'https://jzimg.jzdoctor.com/1575e76b76b0b57bc77e35125e2fdbed.jpeg'
const img2 = 'https://jzimg.jzdoctor.com/1575e76b76b0b57bc77e35125e2fdbed.jpeg'
const img3 = 'https://jzimg.jzdoctor.com/1575e76b76b0b57bc77e35125e2fdbed.jpeg'
const tip1 = 'https://jzimg.jzdoctor.com/ba4f5214fb003ad13098be6a4ddfbdfe.png'
const tip2 = 'https://jzimg.jzdoctor.com/db853e955cc89fa96c993aec7675c006.png'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    topImg: img2,
    tip1,
    tip2,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options: ', options);

    this.getOrderDetail(options)
  },

  getOrderDetail(data) {
    api.orderDetail({
      data,
      success: (res) => {
        console.log('res: ', res);

        if (+res.code === 0) {

          const list = res.data.vaccineOrderItemList.map((item, index) => {
            return {
              id: item.id,
              idStr: this.numberToChinese(index + 1),
              address: item.address,
              genderStr: ['未知', '先生', '女士'][item.gender],
              gender: item.gender,
              name: item.name,
              mobile: item.mobile.replace(/(\d{3})\d*(\d{4})/, '$1****$2'),
              idcardNo: item.idcardNo.replace(/(\d{3})\d*(\d{4})/, '$1********$2'),
              areaName: item.areaName
            }
          })
          let topImg = img2
          //  阿里
          if ([12, 18, 19, 20].includes(parseInt(res.data.vaccineOrder.source))) topImg = img1;
          //  京东
          else if ([13].includes(parseInt(res.data.vaccineOrder.source))) topImg = img3;
          this.setData({
            list,
            topImg
          })
        }
      }
    })
  },
  numberToChinese(number) {
    return ({
      1: '一',
      2: '二',
      3: '三',
      4: '四',
      5: '五',
      6: '六',
      7: '七',
      8: '八',
      9: '九',
      10: '十'
    })[number] || '';
  }
})